<script>
    $(document).ready(function() {
        // Handler for .ready() called.
        $(".datepicker").datepicker({
            showOn: "button",
            buttonImage: "{$BASEURL}/resource/doc/images/icon/calendar.gif",
            buttonImageOnly: true,
            dateFormat: 'yy-mm-dd',
            setDate: new Date(),
            changeMonth: true,
            changeYear: true
        });
        $(".select2").select2();
        
        $('.barang_harga_beli').autoNumeric({
            aSep: '.', aDec: ',', vMax: "999999999999999", vMin: "0"
        });
        //function default_date() {
        //    var today = $.datepicker.formatDate('yy-mm-dd', new Date());
        //    var textfield_date = $("#datepicker").val();
        //    if (textfield_date == '') {
        //         $("#datepicker").val(today);
        //     }
        //}

        //default_date();

        $("#dialog").dialog({
            autoOpen: false,
            draggable: false,
            height: 140,
            width: 230,
            resizable: false,
            modal: true
        });

        $("#pengadaan_att_dist_dialog").dialog({
            autoOpen: false,
            draggable: false,
            height: 500,
            width: 850,
            resizable: false,
            modal: true
        });
        
        $("#dialogPeringatan").dialog({
            autoOpen: false,
            draggable: false,
            height: 140,
            width: 230,
            resizable: false,
            modal: true
        });
        
        $('#gen_pengadaan_ba_dist').click(function() {
            var pengadaan_id        = $(this).attr( "title" );
            var pengadaan_tgl_dist  = $("#pengadaan_tgl_dist").val();
            
            if(pengadaan_tgl_dist.length<=0){
                alert("Isi data tanggal"); 
            }else{
                $.ajax({
                    type: 'POST',
                    data: { 'pengadaan_id': pengadaan_id , 'pengadaan_tgl_dist': pengadaan_tgl_dist},
                    url: '{$config->site_url("inventarisasi/distribusi/generate_nomorserahterima")}',
                    success: function(result) {  
                        var result_length = result.length; 
                        if(result_length>0){ 
                            window.location = '{$config->site_url("inventarisasi/pengadaan/distribusi")}'+'/'+pengadaan_id;
                        }else{
                            alert('gagal generate nomor berita acara');
                        }
                        return false;
                    }
                });
            } 
            // false
            return false;
        }); 

        $('#pengadaan_att_dist').click(function() {
            $("#pengadaan_att_dist_dialog").dialog('open');
        });

    });
</script>
<script language="javascript" type="text/javascript">
    function confirm_action() {
        if (confirm("Apakah anda yakin akan memproses data ini?")) {
            return true;
        }
        return false;
    }
</script> 
<div class="breadcrum">
    <p>
        <a href="#">Inventarisasi</a>
        <span></span><a href="{$config->site_url('inventarisasi/pengadaan')}">Pengadaan</a>
        <span></span><small>Distribusi Barang</small> 
    </p>
    <div class="clear"></div>
</div>
<div class="sub-nav-content">
    <ul>
        <li><a href="{$config->site_url('inventarisasi/pengadaan')}">Pengadaan</a></li>      
        <li><a class="active" href="">Serah Terima / Distribusi Barang</a></li>       
    </ul>
    <div class="clear"></div> 
    <div class="sub-content">
        <div class="table-info-box">
            <h3>No. Pengadaan - {$result_info.pengadaan_nomor|default:''}</h3>
            <table width="100%" class="table-info">
                <tbody> 
                    {if $result_info.pengadaan_tgl_dist|default:'' neq ''}
                        <tr>
                            <th width="15%" valign="top">Tanggal Distribusi</th>
                            <td width="55%">{$dtm->get_full_date($result_info.pengadaan_tgl_dist|default:'')}</td>
                        </tr>
                        <tr>
                            <th width="15%">Nomor Berita Acara</th>
                            <td width="55%">{$result_info.pengadaan_ba_dist|default:''}</td>                           
                        </tr> 
                        <tr>
                            <th width="15%">Surat Berita Acara</th>
                            <td width="55%">
                                {if $result_info.pengadaan_att_dist|default:'' neq ''}
                                    <a class="button-icon" href="{$BASEURL}resource/doc/userfile/distribusi/{$result_info.pengadaan_att_dist}">
                                        <img src="{$BASEURL}/resource/doc/images/icon/preview.png">
                                    </a>  
                                {else}
                                    <p style="color: red;">file surat berita acara belum diupload</p>
                                {/if} 
                            </td>                           
                        </tr> 
                         
                    {/if} 
                    <tr>
                        <th width="15%" valign="top">Bagian</th>
                        <td>{$result_info.bagian_name|default:''}</td>  
                        <td width="30%" align="center" rowspan="2">
                            {if $result_info.pengadaan_generate|default:'0' eq '0' && $result_info.pengadaan_tgl_dist|default:'' neq ''}
                                <form onclick="return confirm('Apakah anda yakin ?')" method="post" action="{$config->site_url('inventarisasi/distribusi/generate_procces')}">
                                    <input type="hidden" value="{$result_info.pengadaan_id}" name="pengadaan_id">
                                    <input type="submit" class="button-process" value="">
                                </form>
                            {elseif $result_info.pengadaan_generate eq '1'}
                                <p style="color: red;font-weight: bolder;">Data Nomor Inventaris telah tergenerate</p>
                            {else}
                                <p style="color: red;font-weight: bolder;">Silahkan isi data distribusi</p>
                            {/if}  
                        </td>
                    </tr> 
                    <tr>
                        <th >Manager</th>
                        <td>{$result_info.bagian_penanggungjawab|default:''}</td>  
                    </tr>  
                    <tr>
                        <th>Tanggal </th> 
                        <td>{$dtm->get_full_date($result_info.pengadaan_date|default:'')}</td> 
                        <td align="center" >
                            <em>Tekan tombol PROSES di atas untuk generate Nomor Inventaris.</em>
                        </td> 
                    </tr> 
                    <tr>
                        <th>Total </th>
                        <td colspan="2" id="total" style="color: red;"><b>Rp. {$total|default:'0'|number_format:2:",":"."}</b></td>                   
                    </tr>
                    <tr>
                        <th>Keterangan</th>
                        <td colspan="2">{$result_info.pengadaan_keterangan|default:''}</td>
                    </tr>
                </tbody>
            </table>
        </div>  
        <div class="clear"></div>
        <!-- notification template --> 
        {include file="base/templates/notification.html"}
        <!-- end of notification template-->
        <form method="post" action="{$config->site_url('inventarisasi/distribusi/beritacara_proccess')}" enctype="multipart/form-data">
            <input type="hidden" size="50" maxlength="100" name="pengadaan_id" id="pengadaan_id" value="{$result_info.pengadaan_id}"/>
            <table width="100%" class="table-input">
                <tbody>
                    <tr class="headrow">
                        <th colspan="2">Distribusi</th>
                    </tr>
                    <tr>
                        <td width="20%">No Berita Acara</td>
                        <td> 
                            <input type="text" size="50" maxlength="100" id="pengadaan_ba_dist" name="pengadaan_ba_dist" value="{$result_info.pengadaan_ba_dist}"/> 
                    
                            <a title="{$result_info.pengadaan_id}" id="gen_pengadaan_ba_dist" href="#" class="button-edit" >Generate No Berita Acara</a> 
                         
                            <small>* wajib diisi</small>
                        </td> 
                    </tr>
                    <tr>
                        <td>Tanggal</td>
                        <td>
                            <input type="text" value="{$result_info.pengadaan_tgl_dist}" readonly="readonly" class="datepicker" size="10" maxlength="10" id="pengadaan_tgl_dist" name="pengadaan_tgl_dist"/><small>* wajib diisi</small>
                        </td> 
                    </tr>
                    <tr>
                        <td>Upload Attachment</td>
                        <td>
                            <input name="pengadaan_att_dist" type="file" /><small>* wajib diisi</small>
                        </td> 
                    </tr> 
                    <tr class="submit-box">
                        <td colspan="3">
                            <input type="submit" class="edit-button" value="Simpan" name="save[insert]"> 
                        </td>
                    </tr>
                </tbody>
            </table> 
        </form>
        <div class="navigation">
            <div class="pageRow">
                <div class="pageNav">
                    <ul>
                        <li class="info"><strong>{$pagination.start|default:'0'} - {$pagination.end|default:'0'}</strong> dari <strong>{$pagination.total|default:'0'}</strong> Data</li>
                        {$pagination.data|default:''}
                    </ul>
                </div>
                <div class="clear"></div>
            </div> 
        </div> 
        <form method="post" action="{$config->site_url('inventarisasi/distribusi/distribusi_proccess')}">
            <input type="hidden" value="{$result_info.pengadaan_id}" name="pengadaan_id">
            <table width="100%" class="table-view">
                <tbody>
                    <tr>
                        <th width="5%">Nomor</th>
                        <th width="13%">No Inventaris</th>
                        <th width="35%">Nama</th> 
                        <th width="5%">Umur <br/>Ekonomis<br/>(tahun)</th> 
                        <th width="15%">Tgl Peroleh</th>
                        <th width="10%">Harga(Rp)</th> 
                        <th width="17%">Ruang</th>  
                    </tr>     
                    {foreach from=$rs_id key=no item=result}
                    <tr {if ($no % 2) <> 0}class="blink-row"{/if}> 
                        <td>{$no+1}</td>
                        <td><b>{$result.barang_noinventaris}</b></td>
                        <td>
                            <input type="hidden" value="{$result.barang_id}" name="barang_id[{$result.barang_id}]"/> 
                            <input type="text" value="{$result.barang_nama}" size="50" maxlength="200" name="barang_nama[{$result.barang_id}]"/> 
                        </td>
                        <td align="right">
                            <input type="text" style="text-align: right;" value="{$result.barang_umurekonomis}" size="4" maxlength="4" name="barang_umurekonomis[{$result.barang_id}]"/>  
                        </td>
                        <td>
                            <input type="text" style="text-align: right;" value="{$result.barang_tglbeli}" readonly="readonly" class="datepicker" size="10" maxlength="10" name="barang_tglbeli[{$result.barang_id}]"/> 
                        </td>
                        <td align="right">
                            <input type="text" style="text-align: right;" class="barang_harga_beli" value="{$result.barang_harga_beli}" size="15" maxlength="20" name="barang_harga_beli[{$result.barang_id}]"/>  
                        </td>
                        <td align="right">
                            <select name="ruang_cd[{$result.barang_id}]" class="select2" style="width: 150px;" >
                                <option value=""></option>
                                {foreach from=$rs_ruang item=ruang}
                                    <option value="{$ruang.ruang_cd}" {if $result.ruang_cd eq $ruang.ruang_cd} selected="selected"{/if}>{$ruang.ruang_nomor}</option>
                                {/foreach}
                            </select>
                        </td>  
                    </tr>
                    {foreachelse}
                    <tr>
                        <td colspan="7">Data masih kosong</td>
                    </tr>
                    {/foreach}
                    {if $rs_id|@count gt 0}
                    <tr>
                        <td colspan="7">
                            <input type="submit" name="simpan" value="Simpan" />
                        </td>
                    </tr>
                    {/if}
                </tbody>
            </table> 
        </form>  
        <div class="button-cetak">
            <a href='{$config->site_url("inventarisasi/distribusi/cetak_nomorserahterima")}/{$result_info.pengadaan_id}' title='no' id='cetak_excel'>Cetak Surat Distribusi</a>
            <div class="clear"></div>
        </div> 
    </div>            
</div> 
<div id="dialogPeringatan" title="Peringatan"></div> 

<div id="pengadaan_att_dist_dialog" title="Attachment">  
    <table width="100%" >
        <tr>
            <td align="center">
                <img src="{$filepath}{$result_info.pengadaan_att_dist|default:''}" width="800px">
            </td>
        </tr>
    </table> 
</div>